<?php

/**
 * This is the model class for table "site_products".
 *
 * The followings are the available columns in table 'site_products':
 * @property string $products_id
 * @property string $products_products_category_id
 * @property string $products_title
 * @property string $products_description
 * @property string $products_thumbnail
 * @property string $products_image
 * @property string $products_input_datetime
 * @property string $products_is_active
 */
class site_products extends CActiveRecord {

    /**
     * Returns the static model of the specified AR class.
     * @return site_products the static model class
     */
    public static function model($className=__CLASS__) {
        return parent::model($className);
    }

    /**
     * @return string the associated database table name
     */
    public function tableName() {
        return 'site_products';
    }

    /**
     * @return array validation rules for model attributes.
     */
    public function rules() {
        // NOTE: you should only define rules for those attributes that
        // will receive user inputs.
        return array(
            array('products_products_category_id, products_title, products_description', 'required'),
            array('products_title', 'length', 'max' => 100),
            array('products_thumbnail, products_image', 'length', 'max' => 255),
            array('products_thumbnail, products_image', 'file', 'types' => 'jpg, gif, png', 'allowEmpty' => true, 'maxSize' => 1024 * 1024 * 1, 'tooLarge' => 'Max filesize 1MB'),
            array('products_thumbnail, products_image', 'unsafe'),
            array('products_is_active', 'length', 'max' => 1),
            array('products_description, products_input_datetime', 'safe'),
            // The following rule is used by search().
            // Please remove those attributes that should not be searched.
            array('products_id, products_title, products_description, products_thumbnail, products_image, products_input_datetime, products_is_active', 'safe', 'on' => 'search'),
        );
    }

    /**
     * @return array relational rules.
     */
    public function relations() {
        // NOTE: you may need to adjust the relation name and the related
        // class name for the relations automatically generated below.
        return array(
            'rel_site_products_to_products_category' => array(self::BELONGS_TO, 'site_products_category', 'products_products_category_id'),
        );
    }

    /**
     * @return array customized attribute labels (name=>label)
     */
    public function attributeLabels() {
        return array(
            'products_id' => 'Products',
            'products_products_category_id' => 'Products Category',
            'products_title' => 'Products Title',
            'products_description' => 'Products Description',
            'products_thumbnail' => 'Thumbnail',
            'products_image' => 'Image',
            'products_input_datetime' => 'Input Date',
            'products_is_active' => 'Is Active',
        );
    }

    /**
     * Retrieves a list of models based on the current search/filter conditions.
     * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
     */
    public function search() {
        // Warning: Please modify the following code to remove attributes that
        // should not be searched.

        $criteria = new CDbCriteria;

        $criteria->compare('products_id', $this->products_id, true);
        $criteria->compare('products_products_category_id', $this->products_products_category_id, true);
        $criteria->compare('products_title', $this->products_title, true);
        $criteria->compare('products_description', $this->products_description, true);
        //$criteria->compare('products_thumbnail', $this->products_thumbnail, true);
        //$criteria->compare('products_image', $this->products_image, true);
        $criteria->compare('products_input_datetime', $this->products_input_datetime, true);
        $criteria->compare('products_is_active', $this->products_is_active, true);

        return new CActiveDataProvider($this, array(
            'criteria' => $criteria,
        ));
    }

}